package com.py.pythink.service.impl;

import com.py.pythink.bo.UserVedioAddBo;
import com.py.pythink.dao.UserVedioDao;
import com.py.pythink.dao.VedioLogDao;
import com.py.pythink.entity.UserVedio;
import com.py.pythink.entity.VedioLog;
import com.py.pythink.service.intf.UserVedioService;
import com.py.pythink.third.BaiduCensorUtil;
import com.py.pythink.util.BeanUtil;
import com.py.pythink.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserVedioServiceImpl implements UserVedioService {
    @Autowired
    private UserVedioDao dao;
    @Autowired
    private VedioLogDao vedioLogDao;
    @Override
    public R save(UserVedioAddBo userVedioAddBo) {
        //敏感词过滤
        if(BaiduCensorUtil.textCensor(userVedioAddBo.getInfo(),userVedioAddBo.getTitle())){
            UserVedio userVedio = BeanUtil.copyBean(UserVedio.class, userVedioAddBo);
            userVedio.setFlag(1);
            userVedio.setCtime(new Date());
            if(dao.insert(userVedio)>0){
                vedioLogDao.insert(new VedioLog(1,"新增成功",userVedio.getUid(),new Date()));
                return R.ok();
            }
            return R.fail();
        }else{
            //记录操作日志
            vedioLogDao.insert(new VedioLog(2,"新增视频存在敏感词，失败",userVedioAddBo.getUid(),new Date()));
            return R.fail();

        }
    }

    @Override
    public R detail(int uid) {
        return R.ok(dao.selectByUid(uid));
    }
}
